package com.example.li.day9_27.mvp.Model;

import com.example.li.day9_27.pojo.RequestData;
import com.example.li.day9_27.pojo.User;
import com.example.li.day9_27.utils.RetrofitData;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public class MainModel implements IMainModel {


    @Override
    public void login(String userName, String psw, final OnLoadCallback callback) {
        Disposable subscribe = RetrofitData.getlogin().login(userName, psw)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<RequestData<User>>() {
                    @Override
                    public void accept(RequestData<User> userRequestData) throws Exception {
                        callback.OnSucceed(userRequestData);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        callback.OnFalie(throwable);
                    }
                });
    }
}
